package com.lanren.common.app;

import android.app.Application;
import android.content.Context;

import com.hjq.toast.ToastUtils;
import com.lanren.common.utils.AppUtils;
import com.lanren.common.utils.LogUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;

/**
 * @ClassName BaseApplication
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2019/9/3 16:43
 * @Version 1.0
 */
public class BaseApplication extends Application {
    private static BaseApplication application;

    public static BaseApplication getApp() {
        return application;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        //判断是否是开发模式
        AppUtils.init(this);
        //初始化log工具
        LogUtils.init(AppUtils.isDebug(), "LRLog");
        //android系统信息
        //初始化toast
        ToastUtils.init(this);
        //初始化刷新控件
        initSmartRefreshLayout();
    }

    /**
     * 设置SmartRefreshLayout全局样式\
     */
    private static void initSmartRefreshLayout() {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(android.R.color.white, android.R.color.black);
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
    }
}
